package com.etc.controller;

import com.etc.entity.RoomType;
import com.etc.service.RoomTypeService;
import com.etc.util.Layui;
import com.github.pagehelper.PageInfo;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@Controller
@RequestMapping("/RoomTypeController")
public class RoomTypeController {

    Logger logger=Logger.getLogger(RoomTypeController.class);
    @Autowired
    RoomTypeService service;

    /**
     * 分页 按条件模糊查找所有房间类型信息
     * 邓玲琪
     * @param rtName
     *@param pageNum
     *@param pageSize
     *@return PageInfo<UserInfo>
     */
    @RequestMapping("/getqueryAllRoomType")
    @ResponseBody
    public Layui getqueryAllRoomType(@RequestParam(value = "pageNum",defaultValue = "1")int pageNum,
                                     @RequestParam(value = "pageSize",defaultValue = "3")int pageSize,
                                     @RequestParam(value = "rtName",defaultValue = "")String rtName){
        PageInfo<RoomType>  pageInfo=service.getqueryAllRoomType(pageNum,pageSize,rtName);
        return Layui.data(pageInfo.getTotal(),pageInfo.getList());
    }
    /**
     * 去重显示房间类型 rtName
     * 邓玲琪
     * @return List<String>集合
     */
    @RequestMapping("/queryRtNameRoomType")
    @ResponseBody
    public List<Object> queryRtNameRoomType(){
        List<Object> list=service.getqueryRtNameRoomType();
        return list;
    }

    /**
     * 查询其他房间类型 rtName
     * @return List<String>集合
     */
    @RequestMapping("/queryOtherRoomType")
    @ResponseBody
    public List<RoomType> queryOtherRoomType(String rtName){
        logger.debug(rtName);
        List<RoomType> list = service.queryOtherRoomType(rtName);
        return list;
    }
    /**
     * 增加房间类型
     * 邓玲琪
     * @param
     * @return boolean int>0 为True  否则为False
     */
    @RequestMapping("/addRoomType")
    public ModelAndView addRoomType(RoomType roomType){
        //调用业务层
        int fian = service.addRoomType(roomType);
        ModelAndView mv=new ModelAndView();
        mv.setViewName("back/roomtypeform");
        return mv;
    }
    /**
     * 根据房间类型编号删除房间类型
     * 邓玲琪
     * @param rtId 房间类型编号
     * @return boolean int>0 为True  否则为False
     */
    @RequestMapping("/delRoomType")
    @ResponseBody
    public int delRoomType(@RequestParam(value = "rtId")String rtId){
        //调用业务层
        int fian = service.delRoomType(rtId);
        return fian;
    }

    /**
     * 添加房间
     * @param rtId
     * @param rtName
     * @param rtBed
     * @param rtPrice
     * @param rtForegift
     * @param rtClRoom
     * @param rtClPrice
     * @param rtRemark
     * @return
     */
    @RequestMapping("/ModifyRoomType")
    @ResponseBody
    public int ModifyRoomType( @RequestParam(value = "rtId",defaultValue = "")String rtId,
                               @RequestParam(value = "rtName",defaultValue = "")String rtName,
                               @RequestParam(value = "rtBed",defaultValue = "0")int rtBed,
                               @RequestParam(value = "rtPrice",defaultValue ="0")float rtPrice,
                               @RequestParam(value = "rtForegift",defaultValue = "0")float rtForegift,
                               @RequestParam(value = "rtClRoom",defaultValue = "0")int rtClRoom,
                               @RequestParam(value = "rtClPrice",defaultValue = "0")float rtClPrice,
                               @RequestParam(value = "rtRemark",defaultValue = "")String rtRemark){
        RoomType roomType=new RoomType(rtId,rtName,rtBed,rtPrice,rtForegift,rtClRoom,rtClPrice,rtRemark);
        int fian = service.ModifyRoomType(roomType);
        return fian;
    }
}
